package com.unionfetch.content_home.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.unionfetch.content_home.R
import com.unionfetch.content_home.bean.TradeAccountModel
import com.unionfetch.content_home.ui.view.AccountCardView

class AccountInfoListAdapter(list: MutableList<TradeAccountModel>) :
    BaseQuickAdapter<TradeAccountModel, BaseViewHolder>(
        R.layout.layout_account_info_item_view,
        list
    ) {
    private var mChildItemClick: ((view: View, position: Int) -> Unit)? = null
    override fun convert(
        holder: BaseViewHolder,
        item: TradeAccountModel
    ) {
        val cardView =
            holder.getView<AccountCardView>(R.id.account_card_view)
        cardView.findViewById<View>(R.id.tv_lever_in_card).setOnClickListener {
            mChildItemClick?.invoke(it, holder.layoutPosition)
        }
        cardView.findViewById<View>(R.id.iv_modify_lever_in_card).setOnClickListener {
            mChildItemClick?.invoke(it, holder.layoutPosition)
        }
        val gotoDeposit = cardView.findViewById<View>(R.id.tv_goto_deposit)
        cardView.findViewById<View>(R.id.ll_deposit_container).setOnClickListener {
            if (gotoDeposit.isEnabled) {
                mChildItemClick?.invoke(it, holder.layoutPosition)
            }
        }
        cardView.setData(item)
    }

    fun setChildItemClickListener(callback: ((view: View, position: Int) -> Unit)) {
        mChildItemClick = callback
    }
}